package com.hulman.oms.web;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.Area;
import com.hulman.oms.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class AreaController
{
	@Autowired
	private AreaService areaService;

	@GetMapping("/areas/{id}")
	public Result findAreaById(@PathVariable Integer id)
	{
		Area area = areaService.findAreaById(id);
		return new Result(area);
	}

	@GetMapping("/areas")
	public Result findAreas(Integer page, Integer limit)
	{
		Map<String, Object> map = new HashMap<>();
		map.put("page", page);
		map.put("limit", limit);
		return areaService.findAreasResult(map);
	}

	@DeleteMapping("/areas/{id}")
	public Result deleteAreaById(@PathVariable Integer id)
	{
		areaService.deleteAreaById(id);
		return Result.SUCCESS;
	}

	@PutMapping("/areas")
	public Result saveArea(Area area)
	{
		areaService.saveArea(area);
		return Result.SUCCESS;
	}

}
